package de.se2.sharebox.classes;

import java.util.Vector;

/**
 *
 * The collection of Accounts, simulate our DB with Accounts
 *
 * @author Gruppe 10
 *
 */
public class AccountsCollection
{

	private Vector<UserAccount> userAccounts = new Vector<UserAccount>();
	private static AccountsCollection instance = null;

	public Vector<UserAccount> getUserAccount()
	{
		return userAccounts;
	}

	/**
	 *
	 */
	private AccountsCollection()
	{
		Log.getInstance().addEntry("AccountsCollection", "AccountsCollection erstellt");
	}

	public static AccountsCollection getInstance()
	{
		if (instance == null)
			instance = new AccountsCollection();

		return instance;
	}

	/**
	 * Konten bekommen
	 */
	public Vector<UserAccount> getAccounts()
	{
		Log.getInstance().addEntry("AccountsCollection", "getAccounts()");
		return this.userAccounts;
	}

	/**
	 * pruefen, ob das Konto existiert
	 *
	 * @param userAccount -
	 *          Nutzerkonto
	 * @return userAccount
	 */
	public boolean checkAccount(UserAccount userAccount)
	{
		Log.getInstance().addEntry("AccountsCollection", "checkAccount " + userAccount.getEmailAdresse());
		return this.userAccounts.contains(userAccount);
	}

	/**
	 * Addierung Konto zur Kontocollection
	 *
	 * @param userAccount -
	 *          Nutzerkonto
	 */
	public boolean addAccount(UserAccount userAccount)
	{
		Log.getInstance().addEntry("AccountsCollection", "Add user " + userAccount.getEmailAdresse());
		return this.userAccounts.add(userAccount);
	}

	/**
	 * Gibt Nutzerkonto per Emailadresse
	 *
	 * @param emailAddres -
	 *          Emailadresse
	 * @return Nutzerkonto
	 */
	public UserAccount getAccountByEmailAddress(String emailAddres)
	{
		Log.getInstance().addEntry("AccountsCollection", "getAccountByEmailAddress " + emailAddres);
		for (UserAccount account : userAccounts)
		{
			if (account.getEmailAdresse().equals(emailAddres))
				return account;
		}
		return null;
	}

	public boolean removeAccount(UserAccount userAccount)
	{
		Log.getInstance().addEntry("AccountsCollection", "Removing user " + userAccount.getEmailAdresse());
		return this.userAccounts.remove(userAccount);
	}

}
